<?php

namespace Biz\model\brandRights;

use Biz\pockets\modelTrait\BizModelTrait;
use Doraemon\pockets\datebase\BaseDbModel;

class BrandLevelRightsConfig extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_store';

    const _DATABASE_ = 'store';

    const _TABLE_NAME = 'brand_level_rights_config';

    const STATUS_ON = BaseDbModel::STATUS_NORMAL;
    const STATUS_DELETE = BaseDbModel::STATUS_DELETE;

    use BizModelTrait;

    /**
     * 获取等级权益
     * @param $level
     * @param $status
     * @return array|bool
     */
    public static function getRightsConfigByLevel($level, $status = null)
    {
        $where['level'] = $level;
        if (isset($status)) {
            $where['status'] = $status;
        }
        return self::dataSelect($where);
    }

    /**
     * 获取等级某个权益
     * @param $level
     * @param $sourceRightsId
     * @param $status
     * @return array|bool
     */
    public static function getOneRightsConfig($level, $sourceRightsId,$status = null)
    {
        $where['level'] = $level;
        $where['rights_source_id'] = $sourceRightsId;
        if (isset($status)) {
            $where['status'] = $status;
        }
        return self::dataSelectInfo($where);
    }

    /**
     * 获取等级权益配置MAP
     * @param $status
     * @return array
     */
    public static function getLevelRightsCfgMap($status = null)
    {
        $where = [];
        if (isset($status)) {
            $where['status'] = $status;
        }
        $result = self::dataSelect($where);
        $data = [];
        if ($result && is_array($result)) {
            foreach ($result as $row) {
                $data[$row['level']][] = $row;
            }
        }
        return $data;
    }


}